# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time        : 2021/10/12 17:55
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : threshold_segment.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
from PIL import Image
from DIP_experiment_4.util import histogram, contrast_show
import numpy as np

img_path = "../experiment_fig/brain.tif"
my_font = "C:/Windows/Fonts/simsun.ttc"
im = Image.open(img_path)
im_arr = np.array(im.getdata()).reshape(im.size)
thresh_im = np.where(im_arr > 130, 255, 0)
im_dict = {"原始图像": im}
histogram(im_dict, subplot_size=(1, 1), xticks=np.arange(0, 255, 10),
          xrotation=45, font=my_font)
im_dict["阈值分割"] = thresh_im
contrast_show(im_dict, (1, 2), font=my_font)
